#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   make_fake_hive_daat.py
@Contact :   fengfeng.qiu@amh-group.com

@Modify Time      @Author
------------      -------
2022/1.csv/22 15:12   qiufengfeng
'''

import random
import math


def make_fake_date():
    year = random.choice([2022,2021])
    if year == 2022:
        month = 1
    else:
        month = random.choice(list(range(1,13)))
    day = random.choice(list(range(1,25)))

    data_str = "%d-%02d-%02d" % (year,month,day)
    return data_str


def generate_random_gps(base_log=120, base_lat=30, radius=1000000):
    radius_in_degrees = radius / 111300
    u = float(random.uniform(0.0, 1.0))
    v = float(random.uniform(0.0, 1.0))
    w = radius_in_degrees * math.sqrt(u)
    t = 2 * math.pi * v
    x = w * math.cos(t)
    y = w * math.sin(t)
    longitude = y + base_log
    latitude = x + base_lat
    # 这里是想保留6位小数点
    loga = '%.6f' % longitude
    lata = '%.6f' % latitude
    return loga, lata




if __name__ == '__main__':

    user_id = list(range(1,100000))
    driver_id = list(range(1,100000))
    cargo_id = list(range(1,1000))

    with open('fake_data.csv','w',encoding='utf-8') as fwrite:
        fwrite.write(",".join(["id" ,"shipper_id","cargo_id","driver_id","driver_responsible","is_contraband_cargo","start_addr_lat","start_addr_lon","end_addr_lat","end_addr_lon","day"]) + "\n")
        for index, cargo in enumerate(cargo_id):
            item = []

            # 自增id
            item.append(index)

            # 用户信息表自增id
            item.append(random.choice(user_id))

            # 货源id
            item.append(random.choice(cargo_id))

            # 司机id
            item.append(random.choice(driver_id))

            # 是否处罚司机
            item.append(random.choice([0,1]))

            # 是否是违禁品货物
            item.append(random.choice([0, 1]))

            # 发货经度,和纬度
            random_lat,random_lot = generate_random_gps()
            item.extend([random_lat,random_lot])

            # 卸货经度,和纬度
            random_lat, random_lot = generate_random_gps()
            item.extend([random_lat, random_lot])





            # 插入day
            item.append(make_fake_date())
            item = [str(i) for i in item]
            #fwrite.write('('+ ",".join(item[:-1.csv]) + ",\""+item[-1.csv]+"\"),\n")
            fwrite.write(",".join(item) + "\n")



